//
//  MainTabbarCenterView.swift
//  funcode
//
//  Created by Wan Jiading on 2017/6/7.
//  Copyright © 2017年 WanJiading. All rights reserved.
//

import UIKit

class MainTabbarCenterView: UIView {
	
	var button: UIButton!
	var titleLabel: UILabel!
	
	//  sns_addfeed_btn  sns_addfeed_selectimg_btn
	convenience init(title: String, imageName: String, selectedImageName: String) {
		self.init()
	
		// 0. 半圆
		let imageView = UIImageView(image: UIImage(named: "tabbar_radio_half_cycle"))
		self.addSubview(imageView)
		imageView.sizeToFit()
		
		// 1. 按钮
		button = UIButton(type: .custom)
		self.addSubview(button)
		button.setImage(UIImage(named: imageName), for: .normal)
		button.setImage(UIImage(named: selectedImageName), for: .selected)
		button.sizeToFit()
		button.isUserInteractionEnabled = false
		
		// 2. 文本
		titleLabel = UILabel()
		self.addSubview(titleLabel)
		titleLabel.font = UIFont.systemFont(ofSize: 8)
		titleLabel.text = title
		titleLabel.sizeToFit()
		
		
		// 设置约束
		imageView.snp.makeConstraints { [unowned self] (make) in
			make.left.equalTo(self)
			make.right.equalTo(self)
			make.bottom.equalTo(self.snp.bottom).offset(-30)
			make.height.equalTo(imageView.height)
		}
		
		button.snp.makeConstraints { [unowned self] (make) in
			make.centerX.equalTo(self)
			make.bottom.equalTo(self.snp.bottom).offset(-20)
			make.width.equalTo(self.button.snp.width)
			make.height.equalTo(self.button.snp.height)
		}
		
		titleLabel.snp.makeConstraints { [unowned self] (make) in
			make.bottom.equalTo(self).offset(-1)
			make.centerX.equalTo(self.button)
			make.size.equalTo(self.titleLabel.size)
		}
	}
	
	func setSelected(_ selected: Bool) {
		button.isSelected = selected
		if (selected) {
			titleLabel.textColor = UIColor.rgb("84a740")
		} else {
			titleLabel.textColor = UIColor.rgb("999999")
		}
		
	}
}
